package cn.adkii.mybatis.session.defaults;

import cn.adkii.mybatis.binding.MapperRegistry;
import cn.adkii.mybatis.mapping.MappedStatement;
import cn.adkii.mybatis.session.Configuration;
import cn.adkii.mybatis.session.SqlSession;

/**
 * @author malingdi
 * @description 实现
 * @date 2023/12/1 18:52
 */
public class DefaultSqlSession implements SqlSession {

    /**
     * 映射器注册机
     */
    private Configuration configuration;

    public DefaultSqlSession(Configuration configuration) {
        this.configuration = configuration;
    }

    @Override
    public <T> T selectOne(String statement) {
        MappedStatement mappedStatement = configuration.getMappedStatement(statement);
        return (T) ("你被代理了！方法：" + statement + ";待执行SQL:" + mappedStatement.getSql());
    }

    @Override
    public <T> T selectOne(String statement, Object parameter) {
        MappedStatement mappedStatement = configuration.getMappedStatement(statement);
        return (T)("你被代理了！ 方法：" + statement + "; 入参：" + parameter  + ";待执行SQL:" +mappedStatement.getSql());
    }

    @Override
    public <T> T getMapper(Class<T> type) {
        return configuration.getMapper(type, this);
    }
}
